package cn.exrick.xboot.modules.content.controller;


import cn.exrick.xboot.common.utils.ResultUtil;
import cn.exrick.xboot.common.utils.SecurityUtil;
import cn.exrick.xboot.common.vo.Result;
import cn.exrick.xboot.config.custom.CustomPage;
import cn.exrick.xboot.modules.base.entity.RolePermission;
import cn.exrick.xboot.modules.base.entity.User;
import cn.exrick.xboot.modules.content.entity.HontUser;
import cn.exrick.xboot.modules.content.entity.HontUserPermission;
import cn.exrick.xboot.modules.content.service.IHontUserPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zy
 * @since 2022-10-26
 */
@RestController
@RequestMapping("/xboot/hontUserPermission")
public class HontUserPermissionController {

    @Autowired
    private IHontUserPermissionService hontUserPermissionServiceImpl;
    @RequestMapping(method = RequestMethod.GET, value = "/selectAllList")
    public Result<Object> selectAllList(){
        List<HontUserPermission> list = hontUserPermissionServiceImpl.selectAllList();
        return ResultUtil.data(list);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/selectPermissionsByUserId")
    public Result<Object> selectPermissionsByUserId(String id){
        List<HontUserPermission> list = hontUserPermissionServiceImpl.selectAllList();
        return ResultUtil.data(list);
    }
    /**
     * 编辑角色分配菜单权限
     * @param roleId
     * @param permIds
     * @return
     */
    @RequestMapping(value = "/editUserPerm",method = RequestMethod.POST)
    public Result<Object> editRolePerm(String userId,
                                       String permIds){
       return hontUserPermissionServiceImpl.editUserPerm(userId,permIds);

    }
    @RequestMapping(value = "/getPermByUserId",method = RequestMethod.GET)
    public Result<Object> editRolePerm(String userId){
        List<HontUserPermission> byHontUserId = hontUserPermissionServiceImpl.findByHontUserId(userId);
        List<String> list=new ArrayList<String>();
        for(int i=0;i<byHontUserId.size();i++){
            list.add(byHontUserId.get(i).getHontPermissionId());
        }
        return ResultUtil.data(list);
    }
}

